package com.shadow.core.net.interceptors;

import com.shadow.core.util.storage.ShadowPreference;

import java.io.IOException;
import java.util.List;

import okhttp3.Response;

/**
 * @author zy
 * on 2018/6/28
 */
public class GetCookieInterceptor extends BaseInterceptor {
    @Override
    public Response intercept(Chain chain) throws IOException {
        Response resp = chain.proceed(chain.request());
        List<String> cookies = resp.headers("Set-Cookie");
        String cookieStr = "";
        if (cookies != null && cookies.size() > 0) {
            for (int i = 0; i < cookies.size(); i++) {
                cookieStr += cookies.get(i);
            }
            ShadowPreference.addCustomAppProfile("Cookie",cookieStr);
        }
        return resp;
    }
}
